{extend name="base"/}
 {block name="content"}
 <div id="header-frame">
 {include file="public:top" /}
 <script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery-2.0.3.min.js'></script>
<script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery.form.js'></script>
<link href="__STATIC__/admin/uploadajax/css/style.css" type="text/css" rel="stylesheet"/>
 </div>
 <div id="frame-body">
 <div id="menu-frame" style="width: 100%;float: left;">
 {include file="public:menu" /}


 </div>
 <div id="main-frame" style="float: left;">
 <div id="dcMain" style="margin-left: 20px;width: 1682px;">
   <!-- 当前位置 -->
<div id="urHere">管理中心<b>></b><strong>Banner</strong> </div>   <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
    <h3><a href="{:url('admin/banner/add_bannertype')}" class="actionBtn">添加管理员</a>网站管理员</h3>

   <h3>
	{foreach name="bannerdata" item="vo"}
   	<a href="{:url('admin/banner/index')}?pid={$vo['banner_id']}" {if condition="$BannerD['banner_id']==$vo['banner_id']"} class="actionBtn" {else /} class="actionBtn" {/if}>{$vo['banner_name']}</a>
   	{/foreach}
    </h3>	
   	  <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
    <tr>
       <th>添加{$BannerD['banner_name']}轮播图</th>
       <th>{$BannerD['banner_name']}轮播图</th>
     </tr>
     <tr>
      <td width="350" valign="top">
        <form id='myupload' action="{:url('banner/uploadifyImg')}" method='post' enctype='multipart/form-data'>
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableOnebor">
         <tr>
          <td><b>首页轮播图名称</b>
			<input type="text" id="bannerm_name" name="bannerm_name" value="" size="20" class="inpMain" />
          </td>
         </tr>
          <tr>
          <td><b>链接</b>
			<input type="text"  name="action" value="" size="50" class="inpMain" />
          </td>
         </tr>
		 <tr>
          <td>	
		     <div style="width:500px;margin:10px auto; border:solid 1px #ddd; overflow:hidden; ">
		  <!-- <form id='myupload' action="{:url('banner/uploadImg')}" method='post' enctype='multipart/form-data'> -->
		    <input type="file" id="uploadphoto" name="images" value="请点击上传图片"  style="display:none;" />
		  <!-- </form> -->
		  <div class="imglist"> </div>
		  <input type="hidden" id="bannerm_img" name="bannerm_img" value=""/>
		  <p class="res"></p>
		  <div class="progress">
		    <div class="progress-bar progress-bar-striped" ><span class="percent"></span></div>
		  </div>
		  <a href="javascript:void(0);" onclick="uploadphoto.click()" class="uploadbtn">点击上传首页轮播图</a>
		</td>
		</tr>  
           <tr>
          <td><b>排序</b>
			<input type="text" name="bannerm_sort" id="bannerm_sort" value="" size="20" class="inpMain" />
		
          </td>
         </tr>
         <tr>
          <td>
                      <input type="hidden" name="token" value="79db104d" />
                      <input type="hidden" name="urlRoute" value="carousel/{$BannerD['banner_id']}"/>
                      <input type="hidden" name="banner_id" value="{$BannerD['banner_id']}"/>
			<input type="button" onclick='bannerM_add()' value="提交" class="btn"/>
          </td>
         </tr>
        </table>
  </form> 
      </td>
      <td valign="top">
       <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableOnebor">
        <tr>
         <td width="100">首页轮播图</td>
         <td width="100">首页轮播图名称</td>
         <td width="100">链接</td>
                  <td width="50" align="center">排序</td>
         <td width="80" align="center">操作</td>
        </tr>
        {foreach name="BannerM" item="vo"}
		                <tr>
         <td><a href="{$vo['action_url']}" target="_blank"><img src="{$vo['img_url']}"  width="400"  height="240" /></a></td>
         <td>{$vo['bitem_name']}</td>
         <td>{$vo['action_url']}</td>
         <td align="center">{$vo['bitem_sort']}</td>
         <td align="center"><a href="{:url('',['bitem_id'=>$vo['bitem_id']])}">编辑</a> | <a href="JavaScript:" onclick="bannerm_dele('确定要下架吗？',{$vo['bitem_id']})">下架</a></td>
        </tr>
         {/foreach}   	          
                
         </table>
              <h3 align="center">{$BannerM[0]?'':'这里没有数据'}</h3>  
      </td>
     </tr>
    </table>

  
  </div>  
 </div>
  </div>
<script type="text/javascript">
$(document).ready(function(e) {
   var progress = $(".progress"); 
   var progress_bar = $(".progress-bar");
   var percent = $('.percent');
   $("#uploadphoto").change(function(){
     $("#myupload").ajaxSubmit({ 
        dataType:  'json', //数据格式为json 
        beforeSend: function() { //开始上传 
            progress.show();
            var percentVal = '0%';
            progress_bar.width(percentVal);
            percent.html(percentVal);
        }, 
        uploadProgress: function(event, position, total, percentComplete) { 
            var percentVal = percentComplete + '%'; //获得进度 
            progress_bar.width(percentVal); //上传进度条宽度变宽 
            percent.html(percentVal); //显示上传进度百分比 
        }, 
        success: function(data) {
            console.log(data);
            if(data.state == 1){
                var src = data.path;  
                var attstr= '<img src="'+src+'">';

                $(".imglist").append(attstr);
                $("#bannerm_img").val(data.path);
                //$(".res").html("上传图片"+data.name+"成功，图片大小："+data.size+"K,文件地址："+data.url);
            }else{
                $(".res").html(data.errmsg);
            }
            progress.hide();        
        }, 
        error:function(xhr){ //上传失败 
           alert("上传失败"); 
           progress.hide(); 
        } 
    }); 
   });

});

function bannerM_add(){
	var id={$BannerD['banner_id']};
	var success_url="{:url('admin/banner/index')}?pid="+id;
	var url="{:url('admin/banner/add_bannerM')}";
	var admins=$("#myupload").serialize();
	$.post(url,admins,function(result){
	 
	if(result.status=='4')
	{
	dialog.success(result.message,success_url);
	}else
	{
		dialog.error(result.message);
	} 
	})
}
</script>
 {/block}